#include<iostream>
#include<vector>
using namespace std;

class Solution1 {
public:
    int maxProfit(vector<int>& prices) {
        int len = prices.size();
        vector<vector<int>> dp(2, vector<int>(len + 3, 0));
        dp[1][0] = -prices[0];
        for (int i = 1; i < len; i++) {
            dp[0][i] = max(dp[0][i - 1], dp[1][i - 1] + prices[i]);
            dp[1][i] = max(dp[1][i - 1], dp[0][i - 1] - prices[i]);
        }
        return dp[0][len - 1];
    }
};


class Solution2 {
public:
    int maxProfit(vector<int>& prices) {
        int len = prices.size();
        int dontHaveYest = 0;
        int HaveYest = -prices[0];
        for (int i = 1; i < len; i++) {
            int dontHaveTod = max(dontHaveYest, HaveYest + prices[i]);
            int HaveTod = max(HaveYest, dontHaveYest - prices[i]);
            dontHaveYest = dontHaveTod;
            HaveYest = HaveTod;
        }
        return dontHaveYest;
    }
};


class Solution3 {
public:
    int maxProfit(vector<int>& prices) {
        int len = prices.size();
        int ans = 0;
        for (int i = 1; i < len; i++) {
            ans += max(0, prices[i] - prices[i - 1]);
        }
        return ans;
    }
};


int main() {
	Solution3 s;
	vector<int> prices = { 7,1,5,3,6,4 };
	cout << s.maxProfit(prices) << endl;
	return 0;
}